package com.woniuxy.microstockserver.mapper;

import com.woniuxy.microstockserver.bean.EnterStockGoodsDetailBean;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @author 赵雄伟
 * 入库商品详情mapper
 */
@Mapper
public interface EnterStockGoodsDetailMapper {
    /**
     * 新增入库单的新增入库商品
     * @param esId
     * @param enterStockGoodsDetailBeanList
     */
    @Insert("<script>" +
            "insert into t_enterstock_goodsdetails_info (fk_goods_id,es_goods_remarks,fk_es_id,delete_status,es_goods_amount) values "+
            "<foreach collection='list' item='goods'  separator=','>"+
            "(#{goods.goodsId},#{goods.esGoodsRemarks},#{esId},#{goods.deleteStatus},#{goods.esGoodsAmount})"+
            "</foreach>"+
            "</script>")
    int saveEnterStockGoodsDetailMapper(@Param("esId") Long esId, @Param("list") List<EnterStockGoodsDetailBean> enterStockGoodsDetailBeanList);

    /**
     * 根据入库单外键id查询入库单详情
     */
    @Results({
            @Result(id = true,property = "id",column = "id",javaType = Long.class),
            @Result(property = "goodsId",column = "fk_goods_id",javaType = Long.class),
            @Result(property = "esGoodsRemarks",column = "es_goods_remarks",javaType = String.class),
            @Result(property = "esId",column = "fk_es_id",javaType = Long.class),
            @Result(property = "deleteStatus",column = "delete_status",javaType = Byte.class),
            @Result(property = "esGoodsAmount",column = "es_goods_amount",javaType = Integer.class)
    })
    @Select("select * from t_enterstock_goodsdetails_info where fk_es_id = #{esId}")
    List<EnterStockGoodsDetailBean> findEnterStockAndGoodsDetail(@Param("esId") Long id);

    /**
     * 根据入库单外键id，删除入库单商品信息，主要用于修改入库单
     * @param id
     */
    @Delete("delete from t_enterstock_goodsdetails_info where fk_es_id = #{esId}")
    void deleteByEsId(@Param("esId") Long id);
}
